package com.otaku.admin.service;

import com.otaku.admin.dao.TokenMapper;
import com.otaku.admin.dao.entity.Token;
import com.otaku.admin.util.NumericTypeConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("tokenService")
public class TokenService {

    @Autowired
    private TokenMapper tokenMapper;

    public List<Token> findByUserId(String userId) {
        return tokenMapper.findByUserId(userId,NumericTypeConstant.TOKEN_STATUS_SUCCESS);
    }

    public Token findByAccessToken(String accessToken,Integer status) {
        return tokenMapper.findByAccessToken(accessToken,status);
    }

    public void updateToken(Token token){
        tokenMapper.updateById(token);
    }

    public Token findByRefreshToken(String refreshToken) {
        return tokenMapper.findByRefreshToken(refreshToken,NumericTypeConstant.TOKEN_STATUS_SUCCESS);
    }

    public void updateStatusByUserId(Integer userId, Integer status) {
        tokenMapper.updateStatusByUserId(userId, status, NumericTypeConstant.TOKEN_STATUS_SUCCESS);
    }

    public void saveToken(Token token) {
        tokenMapper.insert(token);
    }

    public Boolean checkToken(String token, String userId) {
        List<Token> tokenList = tokenMapper.findByTokenAndUserId(token, userId,NumericTypeConstant.TOKEN_STATUS_SUCCESS);
        return false;
    }
}
